package com.example.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.example.entity.College;
import com.example.mapper.CollegeMapper;
import com.example.service.CollegeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CollegeServiceImpl implements CollegeService {
    @Resource
    private CollegeMapper collegeMapper;
    @Override
    public void add(College college) {
        collegeMapper.insert(college);
    }

    @Override
    public PageInfo<College> selectPage(Integer pageNum, Integer pageSize, String name) {
        List<College> list = null;
        PageHelper.startPage(pageNum, pageSize);
        //1.name有值，按照name进行模糊查询
        if (ObjectUtil.isNotEmpty(name)) {
            list = collegeMapper.selectByName(name);
        }else {
            //2.name为空，查询所有
            list = collegeMapper.selectAll();
        }

        return PageInfo.of(list);
    }

    @Override
    public List<College> selectAll(College college) {
        return collegeMapper.selectAll();
    }

    @Override
    public void update(College college) {
        collegeMapper.updateById(college);
    }

    @Override
    public void deleteById(Integer id) {
        collegeMapper.deleteById(id);
    }
}
